package server;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class Morc {

	private BufferedWriter bufferedWriter;
	private File file;

	public Morc() {
		try {
			this.file = new File("Scraps.txt");
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

	public boolean postScrap(String from, String to, String content) {
		try {
			bufferedWriter = new BufferedWriter(new FileWriter(file, true));
			bufferedWriter.write("-----");
			bufferedWriter.newLine();
			bufferedWriter.write("De: " + from);
			bufferedWriter.newLine();
			bufferedWriter.write("Para: " + to);
			bufferedWriter.newLine();
			bufferedWriter.write("Recado: " + content);
			bufferedWriter.newLine();
			bufferedWriter.close();
			return true;
		} catch (Throwable ioe) {
			ioe.printStackTrace();
			return false;
		}
	}

	public String[] getFriends(String user) {
		User u = new User(user);
		String l[] = new String[User.MAX_FRIENDS];
		try {
			l = u.getFriends();

		} catch (Throwable e) {
			e.printStackTrace();
		}
		return l;
	}

	public boolean appendFriend(String user, String friend) {
		User user2 = new User(user);
		return user2.appendFriend(friend);
	}
}
